<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>登录</h1>
    <p>用户名 : <input type="text" id="username"></p>
    <p>密&nbsp;&nbsp;&nbsp;码 : <input type="text" id="password"></p>
    <p><button id="btn">登录</button></p>
</body>
<script>
    document.querySelector('#btn').onclick = function(){
        var username_value = document.querySelector("#username").value;
        var password_value = document.querySelector("#password").value;

        var data = "username=" + username_value + "&password=" + password_value;

        var xhr = new XMLHttpRequest();
        xhr.open("post","./04_project.php");
        xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
        xhr.send(data);
        xhr.onreadystatechange = function(){
            if(xhr.readyState === 4){
                console.log(xhr.responseText);
            }
        }
    }
</script>
</html>